<?php
require_once("../../resources/commons.php");
require_once("../../data/Activity.php");
require_once("../../data/User.php");
require_once("../../data/Item.php");
require_once("dashboard_commons.php");

SessionManager::getInstance()->checkSession();
//A simple script which displays the action associated with the specified Id
if(isset($_REQUEST["id"])){
	displayTop("Reports per activities",null,null);
	$l_activity=Activity::getFromPrimaryKey(base64_decode($_REQUEST["id"]));
	$l_responsibleUser=User::getFromPrimaryKey($l_activity->getResponsibleUser_Id());
	$l_me=SessionManager::getCurrentLoggedUserId();
	if(isset($l_activity) && ($l_responsibleUser->getId()==$l_me || $l_responsibleUser->isUserManager($l_me))){
		$l_reportItems=$l_activity->getAllReportItems();
		if(count($l_reportItems)!=0){
			$l_reportItemsTable=new TableData("ActivitiesTable");
			$l_reportItemsTable->addHeader("created","Created");
			$l_reportItemsTable->addHeader("description","Content");
			$l_reportItemsTable->addHeader("creatingUserFullName","Creating user");
			$l_reportItemsTable->setRecords($l_reportItems);
			echo("<h1>All reports for activity ".$l_activity->getTitle()."</h1>");
			displayTable($l_reportItemsTable);
		}else{
			?>
			<div style="color: white;background-color: red;">No report</div>
			<?php
		}
	}
?>
<center><br/><a href="#" onClick="javascript:history.back(1);"><img border="0" src="<?=ROOT_PATH ?>/apps/resources/images/close.png"/></a></center>
<?php	
	displayBottom();
}else{
	//Redirect to home if invalid parameter is provided
	HTTP::redirect(ROOT_PATH . "/apps/");
}
?>